//
//  ConfigureCell.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/1/20.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "ConfigureCell.h"

#define kLeftMargin 30 / 2
#define kImageViewWidth 40 / 2
#define kLabelLeftMargin 35 / 2
#define kEnterLabelWidth 30 / 2

@implementation ConfigureCell

{
    UIImageView *_iconImageView;
    UILabel *_titleLabel;
    UIImageView *_enterImageView;
    UIView *_separateLine;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.textColor = RGB_COLOR(@"#555555");
        
        _enterImageView = [[UIImageView alloc] init];
        _enterImageView.image = [UIImage imageNamed:@"进入"];
        _enterImageView.contentMode = UIViewContentModeCenter;
        
        self.contentView.backgroundColor = [UIColor clearColor];
        
        [self addSubview:_iconImageView];
        [self addSubview:_titleLabel];
        [self addSubview:_enterImageView];
        [self addSubview:_separateLine];
    }
    return self;
}

- (void)drawRect:(CGRect)rect{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    
    //下分割线
    CGContextSetStrokeColorWithColor(context, [RGB_COLOR(@"#c9c9c9") CGColor]);
    CGContextStrokeRect(context, CGRectMake(kLeftMargin, rect.size.height, rect.size.width - 2 * kLeftMargin, 1));
}

- (void)layoutSubviews{
    _iconImageView.frame = CGRectMake(kLeftMargin, 0, kImageViewWidth, self.height);
    _titleLabel.frame = CGRectMake(_iconImageView.right + kLabelLeftMargin, 0, self.width - 2 *kLeftMargin - kLabelLeftMargin - kImageViewWidth - kEnterLabelWidth, self.height);
    _enterImageView.frame = CGRectMake(self.right - kLeftMargin - kEnterLabelWidth, 0, kEnterLabelWidth, self.height);
//    _separateLine.frame = CGRectMake(kLeftMargin, self.bounds.size.height, UISCREENWIDTH - 2 * kLeftMargin, 1);
}

- (void)configureCellModelWithModelName:(NSString *)modelName{
    if ([modelName isEqualToString:@"我的账户"]) {
        _titleLabel.text = modelName;
        _iconImageView.image = [UIImage imageNamed:modelName];
    }else if ([modelName isEqualToString:@"消息"]){
        _titleLabel.text = modelName;
        _iconImageView.image = [UIImage imageNamed:@"我的消息"];
    }else if ([modelName isEqualToString:@"清除缓存"]){
        _titleLabel.text = modelName;
        _iconImageView.image = [UIImage imageNamed:modelName];
    }else if ([modelName isEqualToString:@"检查更新"]){
        _titleLabel.text = modelName;
        _iconImageView.image = [UIImage imageNamed:modelName];
    }
}

@end
